!function () {
var ie = function () {
  if (!window.ActiveXObject) return false;
  var userAgent = window.navigator.userAgent.toLowerCase();
  var match = userAgent.match(/msie ([\d.]+)/);
  return match && match.length && match[1] || false;
}();

var appendScript = function (src) {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = src;
  script.async = false;
  document.body.appendChild(script);
  return script;
};

var preLoad = {
	 v: window.VERSION || '',
	 assetsHost: window.HOSTS.assets,
	 paths: function () {
    return {
    	 ie: '//' + this.assetsHost + '/supportbox_v2/js/ie.js?v=' + this.v,
      ie_scripts: '//' + this.assetsHost + '/supportbox_v2/js/scripts.ie.js?v=' + this.v,
      ie_vendors: '//' + this.assetsHost + '/supportbox_v2/js/vendors.ie.js?v=' + this.v,
      ie_app: '//' + this.assetsHost + '/supportbox_v2/js/app.ie.js?v=' + this.v,
      scripts: '//' + this.assetsHost + '/supportbox_v2/js/scripts.js?v='+ this.v,
      vendors: '//' + this.assetsHost + '/supportbox_v2/js/vendors.js?v=' + this.v,
      app: '//' + this.assetsHost + '/supportbox_v2/js/app.js?v=' + this.v
    }
  },
	 loadScript: function (src, cb) {
    if (!src || typeof src !== 'string' || !src.length) return;
    var script = appendScript(src);
    script.onload = function () {
      script.onload = null;
      cb && cb();
    };
    script.onreadystatechange = function () {
      var state = script.readyState;
      if (state === 'loaded' || state === 'complete') {
        script.onreadystatechange = null;
        cb && cb();
      }
    }
	 },
  loadScripts: function () {
    var srcs = arguments;
    if (srcs.length === 0) return;
    srcs = Array.prototype.slice.call(srcs);
    for (var i = 0; i < srcs.length; i++) {
      this.loadScript(srcs[i]);
    }
  },
  syncLoadScripts: function () {
    var self = this, srcs = arguments, next;
    if (srcs.length === 0) return;
    srcs = Array.prototype.slice.call(srcs);
    next = function () {
      self.loadScript(srcs.shift(), next);
    };
    next();
  }
};

var paths = preLoad.paths();
if (ie && +ie <= 8) {
  preLoad.syncLoadScripts(paths.ie, paths.ie_scripts, paths.ie_vendors, paths.ie_app);
} else {
  preLoad.loadScripts(paths.scripts, paths.vendors, paths.app);
}
}();
